layui.config({
    base : "/layui/"
}).extend({
    index: 'lib/index'
}).use(['index','form','jquery', 'table',"layer"],function(){
    var form   = layui.form,
        table  = layui.table,
        layer = layui.layer,
        admin  = layui.admin;

    table.render({
        elem: '#applyment_table'
        ,url: '/wXmchUpgrade/queryData'
        ,method:"post"
        ,height: 500
        ,limit:50							//显示数目
        ,limits:[50,100]
        ,cols: [[
            {field:'sub_mch_id', title: '商户号',width:300, "align":"center"},
            {field:'applyment_state', title: '状态',width:150, "align":"center"},
            {field:'applyment_state_desc', title: '状态描述',width:300, "align":"center"},
            {field:'createdTime', title: '创建时间',width:300, "align":"center"}
            ,{field:'OPT', width:300, title: '操作',"align":"center",templet:function (d) {
                    return '<a  href="#" class="layui-btn layui-btn-xs" lay-event="sign_qecode" >签约二维码</a>'+
                    '<a  href="#" class="layui-btn layui-btn-xs" lay-event="applyment_status_query" >查看结果</a>';

                }}
        ]]
        ,request:{
            pageName: 'pageNo' //页码的参数名称，默认：page
            ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
        },
        where:{
            mchUserId :$("#mchUserId").val()
        }
        ,id: 'applyment_table'
        ,page: true
    });


    table.on('tool(applyment_table)', function(obj){

        var table_event = obj.event;

        var data        = obj.data;

        var userId      = $("#mchUserId").val();

        var id          = data.id;


        if(table_event=="applyment_status_query"){

            layer.open({
                type: 1,
                shade: 0.6,
                title: '详细信息',
                shadeClose:true,
                resize:false,
                area: ['90%', '90%'],
                content:"<div><pre>"+data.audit_detail+"</pre></div>"
            });

        }else {

            if(table_event=="sign_qecode"){

                var sign_url = data.sign_url;
                if(sign_url!=undefined && sign_url!="" && sign_url!=null){

                    layer.open({
                        type: 2,
                        shade: 0.6,
                        title: '签约二维码',
                        shadeClose:true,
                        resize:false,
                        area: ['200px', '300px'],
                        content:sign_url
                    });

                }else{
                    layer.msg("还未生成签约二维码",{
                        offset: '32%'
                        ,icon: 2
                        ,time: 3000
                    },function () {
                        layer.closeAll();
                    })

                }

            }
        }

    });
});


